const mongoose=require("mongoose");
let bcrypt=require("bcryptjs")

let Schema=mongoose.Schema

//连接数据库
mongoose
    .connect("mongodb://127.0.0.1:27017/blog",{
        useNewUrlParser:true,
        useUnifiedTopology:true
    }).then(()=>{
        console.log("数据库连接成功")
    })


let userTable=mongoose.model("userTable",new Schema({
    userId:{
        type:Schema.Types.ObjectId
    },
    createTime:{
        type:Date,default:Date.now  //创建时间
    },
    userName:{
        required:true,
        type:String,
        unique:true //唯一性
    },
    userPwd:{
        required:true,
        type:String,
        set(val){
            return bcrypt.hashSync(val,10)
        }
    }
}))

module.exports={
    userTable
}